package ac.rsync.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ac.java.utils.AcDownLoad;
import ac.java.utils.AcHttp;
import ac.java.utils.Vaild;
import ac.rsync.pojo.AcDirFiles;

public class IndexAction extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Map<String,String> varsMap = new HashMap<String,String>();
		varsMap.put("action","list");
		varsMap.put("path","D:\\sql");
		String rs = AcHttp.post("http://localhost:8080/acJrsync/index", varsMap);
		response.getWriter().print(rs);
	}
	
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String action = request.getParameter("action");
		if(null == action)
		{
			return;
		}
		
		if(action.equals("list"))
		{
			String path = request.getParameter("path");
			if(Vaild.isEmpty(path))
			{
				return;
			}
			
			String xml = AcDirFiles.getFsXmlStr(path);
			response.getWriter().print(xml);
		}
		else if(action.equals("download"))
		{
			String path = request.getParameter("path");
			AcDownLoad.getFsHttpResponse(path, response, request);
		}
	}
}